﻿using System.IO;
using NUnit.Framework;

namespace Firestarter.DB.Schema.Test.Logic
{
    [TestFixture]
    public class TestSqlScriptReader
    {
        // ReSharper disable InconsistentNaming
        [Test]
        public void Test_Construct()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var sqlScriptReader = new SqlScriptReader();

            //---------------Test Result -----------------------
            Assert.IsNotNull(sqlScriptReader);
        }


        [Test]
        public void Test_LoadScript_WhenCalledWithSqlScriptFileName_TestFS_OneTableOneUC_OneUCProp_ShouldReturnListOf_X_SqlStatments()
        {
            //---------------Set up test pack-------------------
            var sqlScriptReader =
                new SqlScriptReader();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, sqlScriptReader.SqlStatements.Count); 
            //---------------Execute Test ----------------------
            sqlScriptReader.LoadScript(GetTestSqlScriptStream());
            //---------------Test Result -----------------------

            Assert.AreEqual(38, sqlScriptReader.SqlStatements.Count);
        }
        // ReSharper restore InconsistentNaming


        private static MemoryStream GetTestSqlScriptStream()
        {

            const string testSqlScript = @"USE [master]
										GO

										/****** Object:  Database [TestFS_OneTableOneUC_OneUCProp]    Script Date: 09/11/2010 11:53:09 ******/
										CREATE DATABASE [TestFS_OneTableOneUC_OneUCProp] ON  PRIMARY 
										( NAME = N'TestFS_OneTableOneUC_OneUCProp', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\TestFS_OneTableOneUC_OneUCProp.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
										 LOG ON 
										( NAME = N'TestFS_OneTableOneUC_OneUCProp_log', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\TestFS_OneTableOneUC_OneUCProp_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET COMPATIBILITY_LEVEL = 100
										GO

										IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
										begin
										EXEC [TestFS_OneTableOneUC_OneUCProp].[dbo].[sp_fulltext_database] @action = 'enable'
										end
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET ANSI_NULL_DEFAULT OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET ANSI_NULLS OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET ANSI_PADDING OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET ANSI_WARNINGS OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET ARITHABORT OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET AUTO_CLOSE OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET AUTO_CREATE_STATISTICS ON 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET AUTO_SHRINK OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET AUTO_UPDATE_STATISTICS ON 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET CURSOR_CLOSE_ON_COMMIT OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET CURSOR_DEFAULT  GLOBAL 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET CONCAT_NULL_YIELDS_NULL OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET NUMERIC_ROUNDABORT OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET QUOTED_IDENTIFIER OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET RECURSIVE_TRIGGERS OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET  DISABLE_BROKER 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET DATE_CORRELATION_OPTIMIZATION OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET TRUSTWORTHY OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET ALLOW_SNAPSHOT_ISOLATION OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET PARAMETERIZATION SIMPLE 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET READ_COMMITTED_SNAPSHOT OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET HONOR_BROKER_PRIORITY OFF 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET  READ_WRITE 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET RECOVERY SIMPLE 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET  MULTI_USER 
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET PAGE_VERIFY CHECKSUM  
										GO

										ALTER DATABASE [TestFS_OneTableOneUC_OneUCProp] SET DB_CHAINING OFF 
										GO


										USE [TestFS_OneTableOneUC_OneUCProp]
										GO
										/****** Object:  Table [dbo].[ParentTable]    Script Date: 09/11/2010 10:53:55 ******/
										SET ANSI_NULLS ON
										GO
										SET QUOTED_IDENTIFIER ON
										GO
										CREATE TABLE [dbo].[ParentTable](
											[ParentID] [uniqueidentifier] NOT NULL,
											[UCProp1] [uniqueidentifier] NULL
										 CONSTRAINT [PK_ParentTable] PRIMARY KEY CLUSTERED 
										(
											[ParentID] ASC
										)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
										) ON [PRIMARY]
										GO
										/*CONSTRAINT {0} UNIQUE ({1})*/
										ALTER TABLE [dbo].[ParentTable] Add CONSTRAINT [UC1] UNIQUE ([UCProp1])
										GO
										";


			
            var encodedBytes = System.Text.Encoding.UTF8.GetBytes(testSqlScript);

            return new MemoryStream(encodedBytes);

        }



    }
}